package com.example.homework7;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import androidx.annotation.Nullable;

public class MusicService2 extends Service {
    public MusicService2() {
    }
    private MusicHelper musicHelper = null;

    @Override
    public void onCreate() {
        super.onCreate();
        musicHelper = new MusicHelper(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        musicHelper.destroy();
        musicHelper=null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        musicHelper.play();
        return super.onStartCommand(intent, flags, startId);
    }
    public class MyBinder extends Binder {
        private MusicService2 server;
        public MyBinder(MusicService2 server) {
            this.server = server;
        }
        public void play(){server.musicHelper.play();}
        public void destroy(){server.musicHelper.destroy();}
        public void next(){server.musicHelper.next();}
        public void pause(){server.musicHelper.pause();}
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder(this);
    }
}